package co.yixiang.retail.common.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import co.yixiang.common.mproot.domain.BaseDomain;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.models.auth.In;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "yx_balance_change")
public class YxBalanceChange {

    /**  ID  */
    private Integer id;

    /**  用户id  */
    private Integer uid;

    /**  变化前余额  */
    private BigDecimal changeTurn;

    /**  变化金额  */
    private BigDecimal userFront;

    /**  变化后余额  */
    private BigDecimal changePut;

    /**  余额变化时间  */
    private Date userTime;

    /**  余额变化类型  */
    private Integer type;

    public void changeBaseInfo(YxUser yxUser,BigDecimal userFront){
        this.uid = yxUser.getUid().intValue();
        this.changeTurn = yxUser.getStoreBalance();
        this.userFront = userFront;
        this.changePut = yxUser.getStoreBalance().add(userFront);
        this.userTime = new Date();
        this.type = 6;
    }

    public void refuseBill(YxUser yxUser,BigDecimal refund){
        this.uid = yxUser.getUid().intValue();
        this.changeTurn = yxUser.getStoreBalance();
        this.userFront = refund;
        this.changePut = yxUser.getStoreBalance().add(refund);
        this.userTime = new Date();
        this.type = 7;
    }

    public void copy(YxBalanceChange source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
